const Mock = require("mockjs");
const getResponseObject = require("./dataType");

const Random = Mock.Random;

module.exports = [
  // 例子

  // 普通的get请求
  {
    url: "/api/test1",
    method: "get",
    response(req, res) {
      res.json({
        errno: 0,
        data: {
          name: Random.cname(),
        },
      });
    },
  },
  // get请求带路由参数
  {
    url: "/api/test2/:id",
    method: "get",
    response(req, res) {
      res.json({
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
        },
      });
    },
  },
  // post请求
  {
    url: "/api/getNum",
    method: "post",
    response(req, res) {
      const params = req.body.params;
      res.json({ ...getResponseObject(), data: params + 1 });
    },
  },
  // post请求
  {
    url: "/api/getNumType",
    method: "post",
    response(req, res) {
      const params = req.body.params;
      res.json({
        ...getResponseObject(),
        data: {
          data: { num: params + 1 },
          type: "getNumType",
        },
      });
    },
  },
  // post请求
  {
    url: "/api/getName",
    method: "post",
    response(req, res) {
      // const params = req.body.params;
      res.json({
        ...getResponseObject(),
        data: {
          data: { name: Random.name() },
          type: "getName",
        },
      });
    },
  },
  {
    url: "/api/noResponse",
    method: "post",
  },
];
